<?php
namespace Ygcl\Service;
use Think\Model;
class LessonService extends Model {
	
	private $m;
	
	function __construct(){
		$this->m = D('YgclLesson');
	}
	
	public function _get_lesson_info($lid){
		$paynumber = R('Api/Lessonapi/getnumberbylid',array('lid'=>$lid));
		$data = $this->m->where(array('id'=>$lid))->relation(true)->find();
		$data['paynumber'] = $paynumber;
		return $data;
	}
	
	
// 	//更新已支付人数
//    public function _update_lesson_paynumber($cid){
//    		$con['cid'] = $cid;
//    		$con['status'] = 1;
//    		$info = D('YgclLesson')->where($con)->relation(true)->select();

//    		foreach ($info as $if){
//    			$classinfo = D('YgclClass')->where('id = '.$cid)->relation(true)->find();
//    			$map['status'] = 1;
//    			$map['termid'] = F('Termdata')['id'];
//    			$map['xiaoqu'] = array('eq',$classinfo['district']);
//    			$map['banji'] = array('eq',$classinfo['title']);
//    			$map['lessonname'] = array('eq',$if['lessonname']);
//    			$count = D('YgclOrder')->where($map)->count();
   			 
//    			$data['paynumber'] = $count;
//    			$this->m->where('id = '.$if['id'])->save($data);
//    		}

//    }
   
   //生成课程缓存
   public function _create_cache_lesson($cid){
   		$classtype = F('ClassType/classtype_'.$cid);
   		if($classtype){
   			foreach ($classtype as $key=> $ct){
   				$data[$key]['lessontype'] = $ct;
   				$where['lessontype'] = $ct['id'];
   				$where['cid'] = $cid;
   				$where['status'] = 1;
   				$data[$key]['lesson'] = $this->m->where($where)->order('id desc')->select();
   			}
   		}else{
   			$where['lessontype'] = 0;
   			$where['cid'] = $cid;
   			$where['status'] = 1;
   			$data['lessontype'] = 0;
   			$data[0]['lessontype'] = 'none';
   			$data[0]['lesson'] = $this->m->where($where)->order('id desc')->select();
   		}
	   	F('Lesson/lesson_'.$cid,$data);
   }
}